//
//  MZAtomic.swift
//  MZTool
//
//  Created by gby on 2023/2/9.
//

import Foundation

@propertyWrapper
final class MZAtomic<Value>{
    
    private var lock: NSRecursiveLock = NSRecursiveLock()
    
    private var value: Value
    
    var wrappedValue: Value{
        get{
            lock.lock(); defer { lock.unlock() }
            return value
        }
        
        set {
            lock.lock(); defer { lock.unlock() }
            value = newValue
        }
    }
    
    init(wrappedValue: Value){
        self.value = wrappedValue
    }
}
